import { _decorator, Component, Node, utils } from 'cc';
import Util from './Util';
const { ccclass, property } = _decorator;

@ccclass('GlobeData')
export default class  GlobeData{
   
    //创建本类的全局调用变量
    public static _instance:GlobeData = null
    public static get Instance(){
        if (null == this._instance) {
            this._instance = new GlobeData();
        }
        return this._instance;
    }

    freeCount:number=0;
    startType:number=1;//1是分享 2是视频
    day:number=0;


    setFreeCount(){
        Util.Instance.set("freeCount",this.freeCount);
        Util.Instance.set("day",this.getTodayDate());
    }
    setStartType(){
        Util.Instance.set("startType",this.startType);
    }

    getFreeCount(){
       this.freeCount=GlobeData.Instance.getInt("freeCount",3);
       this.startType=GlobeData.Instance.getInt("startType",1);
       this.day=GlobeData.Instance.getInt("day",this.getTodayDate());
       if(this.getTodayDate()!=this.day){//新的一天
            this.freeCount=3;
            this.startType=1;
            this.setFreeCount();
            this.setStartType();
       }
    }
    getInt(_key, def) {
        let ds = Util.Instance.get(_key);
        if (ds == "" || ds == null || ds == undefined || ds == 'NaN') {
          Util.Instance.set(_key, def);
          ds = def;
        }
        return Number(ds)
    }

    getTodayDate():number{
        const today: Date = new Date();
        const day: number = today.getDate();
        return day;
    }

    loadingInitData(){
        this.getFreeCount();
    }

}


